//
//  HomeClassesView.m
//  AskDoctor
//
//  Created by Li Ming on 2016/12/20.
//  Copyright © 2016年 ly. All rights reserved.
//

#import "HomeClassesView.h"
#import "HomeClassesFlowLayout.h"
#import "HomeClassesCellCollectionViewCell.h"

@interface HomeClassesView ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property(strong,nonatomic)NSArray *homeImageArray;
@property(strong,nonatomic)NSArray *homeNameArray;

@end

static NSString *cellID = @"cellID";

@implementation HomeClassesView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    
    if (self) {
        [self geData];
        [self setupUI];
    }
    return self;
}

-(void)setupUI{
    self.backgroundColor = [UIColor darkGrayColor];
    
    HomeClassesFlowLayout *flowLayout = [HomeClassesFlowLayout new];
    
    //建立界面
    UICollectionView *collectinView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:flowLayout];
    
    [self addSubview:collectinView];
    
    [collectinView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.equalTo(self);
        
    }];
    
    collectinView.delegate = self;
    collectinView.dataSource = self;
    
    [collectinView registerNib:[UINib nibWithNibName:@"HomeClassesCellCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:cellID];
    
    //[collectinView registerClass:[HomeClassesCellCollectionViewCell class] forCellWithReuseIdentifier:cellID];
    
    collectinView.bounces  = NO;
    
}

-(void)geData{
    
    NSArray *nameArray = @[@"肿瘤",@"心血管",@"神经科",@"血液科",@"骨科",@"公益"];
    self.homeNameArray = nameArray;
    NSMutableArray *muArray = [NSMutableArray new];
    
    for (int i = 0; i<6; i++) {
        
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"gt%02d",i+1]];
        
        [muArray addObject:image];
        
    }
    self.homeImageArray = muArray.copy;
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 6;
    
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    HomeClassesCellCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
    
    cell.imageView.image = self.homeImageArray[indexPath.item];
    cell.nameLable.text = self.homeNameArray[indexPath.item];
    cell.backgroundColor = [UIColor whiteColor];
    
    return cell;
    
}

#pragma mark
#pragma mark delegate

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
}

//懒加载
-(NSArray *)homeImageArray{
    
    if (!_homeImageArray) {
        
        _homeImageArray = [[NSArray alloc]init];
        
    }
    
    return _homeImageArray;
    
}

@end
